<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录界面</title>
    <link rel="stylesheet" href="../libs/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../libs/nprocess/css/nprogress.css">
    <link rel="stylesheet" href="../libs/font-awesome/css/font-awesome.css">
    <link rel="stylesheet" href="../css/adminCommon.css">
    <link rel="stylesheet" href="../css/login.css">
</head>

<body>
    <section class="login">
        <div class="login-wrap">
            <img src="../upload/default.png" alt="" class="avatar">
            <form action="" class="form-horizontal">
                <div class="form-group">
                    <label for="" class="control-label">邮箱</label></label></label>
                    <input type="email" id="email" class="form-control" placeholder="邮箱">
                </div>
                <div class="form-group">
                    <label for="" class="control-label">密码</label>
                    <input type="password" id="password" class="form-control" placeholder="密码">
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-login btn-primary btn-block">登录</button>
                </div>
            </form>
        </div>
    </section>
</body>
@@include("../common/base.html")
<!-- <script src="../js/admin/login.js"></script> -->
<script>
    $(function () {
        $(".btn-login").click(function (e) {
            e.preventDefault()
            // console.log("进入提交表单")
            const email = $("#email").val()
            const password = $("#password").val()
            if (!email.trim()) {
                // console.log("--111111---")
                alert("请输入邮箱")
                return
            }
            if (!password.trim()) {
                alert("请输入密码")
                return
            }
            const params = {
                email: email,
                password: password,
            }
            // console.log("----------", params)
            $.ajax(`${baseUrl}/login`, {
                type: 'post',
                data: params,
                success: function (res) {
                    console.log("登录成功：", res)
                    const token = res.token
                    if (token) {
                        localStorage.setItem("token", token)
                        location.href = "/admin/index.html"
                    } else {
                        alert("登录失败！")
                    }
                },
                error: function (err) {
                    console.log("登录失败：", err)
                },
            })
        })
    })
</script>

</html>